/**
 * Copyright 2023 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_
#define MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_

#include <string>
#include <unordered_set>
#include "mindapi/base/macros.h"
#include "utils/ms_utils.h"

namespace mindspore {
// Manager for auto delete temp files
class MS_CORE_API TempFileManager {
 public:
  static TempFileManager &GetInstance();
  /// \brief register temp file which will delete when process exits.
  ///
  /// \param[in] the temp file path.
  void Register(const std::string &file_path);

  /// \brief unregister temp file which is no need to delete when process exits.
  ///
  /// \param[in] the file path.
  void UnRegister(const std::string &file_path);

  /// \brief delete file.
  ///
  /// \param[in] the file path.
  void RemoveFile(const std::string &file_path) const;

  /// \brief delete all temp files
  void CleanTempFiles();

 private:
  TempFileManager() = default;
  ~TempFileManager();
  DISABLE_COPY_AND_ASSIGN(TempFileManager)
  std::unordered_set<std::string> temp_file_paths_;
};
}  // namespace mindspore
#endif  // MINDSPORE_CORE_UTILS_TEMP_FILE_MANAGER_H_
